import { Controller, Get, HttpStatus } from '@nestjs/common';
import { MessageService } from './message.service';
import {
  ApiBearerAuth,
  ApiOperation,
  ApiResponse,
  ApiTags,
} from '@nestjs/swagger';
import { GrpcMethod, MessagePattern } from '@nestjs/microservices';
import { RequireLogin } from '@app/auth/utils/guard';
import { PublicVoError, PublicVoSuccess } from '@app/utils/publicVo';
@ApiTags('用户系统-消息中心')
@Controller('message')
export class MessageController {
  constructor(private readonly messageService: MessageService) {}
  /**
   * TCP 模块
   */
  @MessagePattern('get-message')
  getListTCP(data: any) {
    const { pageNum, pageSize } = data.query;
    return `消息列表 (TCP) - 页码: ${pageNum}, 页数: ${pageSize}`;
  }
  /**
   * HTTP 模块
   */
  @Get()
  @ApiBearerAuth()
  @RequireLogin()
  @ApiOperation({
    summary: '消息列表',
    description: '消息列表接口',
  })
  @ApiResponse({
    status: HttpStatus.OK,
    description: '请求成功',
    type: PublicVoSuccess,
  })
  @ApiResponse({
    status: HttpStatus.BAD_REQUEST,
    description: '请求失败',
    type: PublicVoError,
  })
  getList() {
    return '消息中心列表';
  }

  /**
   * gRPC 跨语言通信
   * @param data  客户端 调用传递数据
   * @returns 服务端 返回调用方法数据
   */
  @GrpcMethod('UserService', 'GetUser') // 这里的 'UserService' 和 'GetUser' 对应 proto 文件中的服务名和方法名
  getUser(data: { id: number }): { id: number; name: string } {
    return { id: data.id, name: 'John Doe' }; // 模拟返回一个用户
  }
}
